package com.travel.haoma.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.View;

import com.travel.haoma.R;
import com.travel.haoma.view.EditImageView;

import java.io.FileNotFoundException;

import cn.haoma.base.common.BaseActivity;
import cn.haoma.base.common.Id;
import cn.haoma.base.common.LayoutId;
import cn.haoma.base.img.ImgUtil;

/**
 * Created by 磊 on 2015/9/4.
 */
@LayoutId(R.layout.act_edit_pic)
public class ActEditPic extends BaseActivity{
    @Id(R.id.edit_img)
    private EditImageView editImageView;
    private Bitmap bitmap;
    public static Intent newIntent(Context context,String path){
        return new Intent(context,ActEditPic.class).putExtra("path",path);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        Bitmap markBitmap = BitmapFactory.decodeFile(getIntent().getStringExtra("path"),options);
        int width = options.outWidth;
        int height = options.outHeight;
        int maxWidth = getScreenPoint().x;
        int maxHeight = getScreenPoint().y;
        float scaleX = width*1.0f/maxWidth;
        float scaleY = height*1.0f/maxHeight;
        float scale = Math.max(scaleX,scaleY);
        options.inJustDecodeBounds = false;
        options.inSampleSize = (int) Math.ceil(scale);
        markBitmap = BitmapFactory.decodeFile(getIntent().getStringExtra("path"),options);
        editImageView.setImageBitmap(markBitmap);
    }


    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()){
            case R.id.title_back:
                finish();
                break;
            case R.id.bt_filter:
                editImageView.setMode(EditImageView.MODE_FILTER);
                break;
            case R.id.bt_edit:
                editImageView.setMode(EditImageView.MODE_EDIT);
                break;
        }
    }
}
